﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AviumX.AviumCore.WinAPI
{
    class Windows
    {
        //The windows running Can be changed Soon - Toxickill
        private static Window[] windows = new Window[50];
        private static uint index = 0;
        public static Boolean Running = true;
        public static void StartAWindow(Window w)
        {
            //Makes a new window
            windows[index] = w;
            index += 1;
        }
        public static uint GetCurrentPrograms()
        {
            //The current amount of programs running.
            return index;
        }
        public static void RemoveClosedWindows()
        {
             // Removes the current window if we close it.
            if (windows[index - 1].Runing == false)
            {
                windows[index - 1] = new Window(0, 0, 0, 0, "");
                index -= 1;
            }
        }
        public static void UpdateAllWindows()
        {
            //Remove any windows that need to be closed.
            RemoveClosedWindows();
            /*
             * Draw the windows, and update the infront one, example: close event, click event ect..
             */
            for (int i = 0; i < index; i++)
            {
                if (i == index - 1)
                {
                    windows[i].infront = true;
                    windows[i].Update();
                }
                else
                {
                    windows[i].infront = false;
                }
                windows[i].Draw();
            }
        }
        public static bool CheckForContact(int x, int y, int width, int height)
        {
            bool go = true;
            for (int i = 0; i < index; i++)
            {
                //Less than X & y
                if (windows[i].location.x < x && windows[i].location.x + windows[i].width > x && windows[i].location.y < y && windows[i].location.y + windows[i].height > y)
                {
                    return false;
                }
                //Greater than X & y
                else if (windows[i].location.x > x && windows[i].location.x < x + width && windows[i].location.y > y && windows[i].location.y < y + height)
                {
                    return false;
                }
                else if (windows[i].location.y > y && windows[i].location.y < y + height && windows[i].location.x < x && windows[i].location.x + windows[i].width > x)
                {
                    return false;
                }
                else if (windows[i].location.x > x && windows[i].location.x < x + width && windows[i].location.y < y && windows[i].location.y + windows[i].height > y)
                {
                    return false;
                }
                else if (windows[i].location.x <= x && windows[i].location.x + windows[i].width >= x && windows[i].location.y <= y && windows[i].location.y + windows[i].height >= y)
                {
                    return false;
                }
                else if (windows[i].location.x >= x && windows[i].location.x <= x + width && windows[i].location.y <= y && windows[i].location.y + windows[i].height >= y + height)
                {
                    return false;
                }
            }
            return go;
        }
    }
}
